/**
 * Created by weidong on 14-2-21.
 */

var log = require("../lib/log");
var cfg = require('../config');
var url = require('url');
var querystring = require('querystring');
var db = require('../lib/db.js');


//进行广告投放
exports.portallinkservlet = function(request,response)
{
    if(request.method.toUpperCase() === "GET")
    {
        console.log("2.[request]adwifi投放广告："+request.url );

        console.log("2.[response]adwifi投放广告："+request.url );
        response.redirect("/adshow.html?userid=1&customerid=1");

    }
    else
    {
        response.render("404.html");
    }

}


var ConThirdQuery = function(request)
{
    //对应关系
    //param[0]=null                            //null
    //param[1]=guwangtest121                   //ssid
    //param[2]=192.168.1.4                     //wlanuserip
    //param[3]=A0%3A88%3AB4%3A8E%3AD9%3A18     //wlanusermac
    //param[4]=192.168.1.1%3A3834              //gwip
    //param[5]=7f1fbb08                        //token
    //param[6]=00%3A19%3AE0%3A00%3A00%3A11     //apmac
    //param[7]=ZTE00000                        //apsn
    //param[8]=http%3A%2F%2Fwww.baidu.com%2F   //wlanuserfirsturl
    //param[9]=121.199.39.232                  //adwifiip
    //param[10]=80                             //adwifiport

    var retstring = '';
    var param = {};
    param[0] = "null";
    param[1] = request.query.ssid;
    param[2] = request.query.wlanuserip;
    param[3] = request.query.wlanusermac;
    param[4] = request.query.gwip;
    param[5] = request.query.token;
    param[6] = request.query.apmac;
    param[7] = request.query.apsn;
    param[8] = request.query.wlanuserfirsturl;
    param[9] = cfg.static_host
    param[10] = 8080;

    for(i=0;i<=10;i++)
    {
        retstring = retstring + "-" + param[i];

    }


    //url encode;substring 去掉第一个 “-”
      retquery = "sntype=WB&state=" + encodeURIComponent(retstring.substring(1,retstring.length));

    console.log("[PortalLinkServlet]:constract return to Third App URL of Query String  = " + retquery);
    return retquery;

}